home *** CD-ROM | disk | FTP | other *** search
- package sun.beanbox.simpleresource;
-
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.net.URLConnection;
- import sun.beanbox.SimpleClassLoader;
-
- public class SimpleResourceConnection extends URLConnection {
- private static boolean debug;
- private Object resource;
- private String cookie;
- private String name;
- private final String prefix = "SIMPLE";
- private final int prefixLength = "SIMPLE".length();
-
- protected SimpleResourceConnection(URL var1) throws MalformedURLException, IOException {
- super(var1);
- this.debug("SimpleResourceConnection(" + var1 + ")");
- String var2 = var1.getFile();
- if (var2.startsWith("/")) {
- var2 = var2.substring(1);
- }
-
- if (!var2.startsWith("SIMPLE")) {
- throw new MalformedURLException("SimpleResource file should start with /SIMPLE");
- } else {
- this.cookie = var2.substring(this.prefixLength, var2.indexOf("/+/"));
- this.name = var2.substring(var2.indexOf("/+/") + 3);
- this.debug(" cookie: " + this.cookie);
- this.debug(" name: " + this.name);
- }
- }
-
- public void connect() throws IOException {
- this.debug("Looking for " + this.cookie + ", " + this.name + " in SimpleResourceLoader");
- Object var1 = SimpleClassLoader.getLocalResource(this.cookie, this.name);
- if (var1 == null) {
- this.debug("Invalid resource name");
- this.resource = null;
- } else {
- this.debug("Found resource " + var1);
- this.resource = var1;
- }
- }
-
- public Object getContent() throws IOException {
- if (!super.connected) {
- this.connect();
- }
-
- return this.resource;
- }
-
- public InputStream getInputStream() throws IOException {
- if (!super.connected) {
- this.connect();
- }
-
- return this.resource instanceof InputStream ? (InputStream)this.resource : SimpleClassLoader.getLocalResourceAsStream(this.cookie, this.name);
- }
-
- private void debug(String var1) {
- if (debug) {
- System.err.println(var1);
- }
-
- }
- }
-